###########################################################################
###		Library Make include file				###
###   									###
###  lib.mk								###
###									###
###########################################################################

###################################################
### Imported variables:				###
###						###
### OBJECTS = 					###
### PROGFLAGS = 				###
### PROGLIBS =					###
### DISTFILES =					###
### LIBPROGS = 					###
### PROGDEFS = 					###
### PRE = 					###
###################################################

#################################################
# before including this file:			#
#						#
#include ../common.mk				#
#LIBTARGET := $(OUTPUTLIB)/lib$(TARGET).a	#
#all: $(PRE) $(LIBTARGET)			#
#################################################



LIBS = 
#LDFLAGS = 
LDFLAGS = -g
DEFS   +=  $(PROGDEFS)
CFLAGS +=  $(PROGFLAGS) -I${PROJECT_BASE}

.SUFFIXES=$(objdir)/%.o %.c %.o %.C %.cpp %.d

OBJ_OUT = $(foreach file, $(OBJECTS) $(CPPOBJECTS) $(CCOBJECTS), $(objdir)/$(file))
SRC_OUT = $(OBJECTS:.o=.c) $(CPPOBJECTS:.o=.cpp) $(CCOBJECTS:.o=.cc)


INC = -I. -I.. -I$(incdir) -I$(srcdir)
ifeq ($(OS),Windows_NT)
   LARGELIB = rvsip
LARGELIBTARGET = $(libdir)/lib$(LARGELIB).a
endif

ifneq ($(words $(API_FILES)),0)
    API_OUT := $(foreach file, $(API_FILES), $(incdir)/$(API_DIR)/$(file))
else
    API_OUT :=
    API_DIR :=
endif 

$(incdir)/$(API_DIR)/%.h: %.h
	$(COPY) "$<" "$@"

$(incdir)/$(API_DIR)/%.hpp: %.hpp
	$(COPY) "$<" "$@"
	
ifneq ($(SUNWS),on)
  ifneq ($(OS), Windows_NT)

    DEP_OUT = $(OBJ_OUT:.o=.d)

    ifeq ($(OS), HP-UX)
      include $(DEP_OUT)
    else
     sinclude $(DEP_OUT)
    endif

    $(objdir)/%.d: %.c  $(objdir)/null
	$(SHELL) -ec "$(CC) -M $(INC) $(DEFS) $(CFLAGS) -c $(CPPFLAGS) $< | sed 's/$*\.o/$(subst /,\/,$(objdir)/$*.o) $(subst /,\/,$(objdir)/$*.d)/g' > $@"

    $(objdir)/%.d: %.cc  $(objdir)/null
	$(SHELL) -ec "$(CC) -M $(INC) $(DEFS) $(CFLAGS) -c $(CPPFLAGS) $< | sed 's/$*\.o/$(subst /,\/,$(objdir)/$*.o) $(subst /,\/,$(objdir)/$*.d)/g' > $@"

    $(objdir)/%.d: %.cpp  $(objdir)/null
	$(SHELL) -ec "$(CPP) -M $(INC) $(DEFS) $(CFLAGS) -c $(CPPFLAGS) $< | sed 's/$*\.o/$(subst /,\/,$(objdir)/$*.o) $(subst /,\/,$(objdir)/$*.d)/g' > $@"
  endif
endif 

$(objdir)/%.o: %.cpp
	$(CPP) $(CFLAGS) -c $< $(CPPFLAGS) $(DEFS) $(INC) -o $@

$(objdir)/%.o: %.cc
	$(CPP) $(CFLAGS) -c $< $(CPPFLAGS) $(DEFS) $(INC) -o $@

$(objdir)/%.o: %.c 
	$(CC) $(INC) $(CFLAGS) -c $< $(CPPFLAGS) $(DEFS) -o $@

$(LIBTARGET): $(objdir)/null $(OUTPUTLIB)/null $(OBJ_OUT) $(DEP_OUT) $(incdir)/$(API_DIR)/null $(API_OUT)
	$(RM) -f $@
	$(AR) $(ARFLAGS) $@ $(OBJ_OUT)
	-$(RANLIB) $@

lint:
	$(LINT) $(LINT_FLAGS) $(INC) $(DEFS) $(CFLAGS) $(SRC_OUT)

subdir = src
check:

ifeq ($(SHELL_TYPE),dos)
%/null:
	IF NOT EXIST "$(dir $@)" MKDIR "$(dir $@)"
	IF NOT EXIST "$@" ECHO null > "$@"
else
%/null: 
	if ( test ! -f $@) ; then \
		mkdir -p $(dir $@); \
		echo "" > $@; \
	fi
endif

clean:
rm:
	$(RM) -f $(LIBTARGET) *.o core $(OBJ_OUT) $(DEP_OUT)

rmt:
	$(RM) -f $(LIBTARGET) core

mostlyclean: clean

depend:
	makedepend *.c *.C *.cpp $(INC) $(PROGFLAGS)

distclean: clean
	$(RM) -f Makefile

realclean: distclean
	$(RM) -f TAGS

distdir = ../`cat ../distname`/$(subdir)
dist: $(DISTFILES)
	for file in $(DISTFILES); do \
	  ln $$file $(distdir) \
	    || { echo copying $$file instead; cp -p $$file $(distdir);}; \
	done

version:
	@echo Version:$(VERSION) By $(AUTHOR)

run:
	@echo Only application can run.

gdb:
	@echo Only application can run.

valgrind:
	@echo Only application can run.

# Tell versions [3.59,3.63) of GNU make not to export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

